<%@page import="backend.User"%>
<%@page import="backend.db.ORM"%>
<script type="text/javascript" src="shared/displayTable.js"></script>
<link rel="stylesheet" type="text/css" href="style/usersTable.css" />
<div id="main-allUsers" style="text-align:center;">
	<fieldset>
		<legend>All users: </legend>
		<%
			boolean admin = request.isUserInRole("administrator");
		%>
		<table style="width:100%;">
				<tr id="firstTr" style="display: none;">
					<th style="width:30%;">username</th>
					<th style="width:15%;">Role</th>
					<th style="width:35%;">Full name</th>
					<th style="width:15%;">Phone number</th>
					<%if (admin) { %><th style="width:5%;">View?</th><%} %>
				</tr>
				<%
					Iterable<User> users = ORM.getAllUsers();
					int size = 0;
					for (User user : users) {
				%>
				<tr id="trOfTable<%=size %>" style="display: none;">
					<td><%=user.username %></td>
					<td><%=user.role %></td>
					<td><%=user.name %></td>
					<td><%=user.phone %></td>
					<%if (admin) { %><th><a href="#" onclick="loadPage('admin/viewStudent.jsp?username=<%=user.username %>');">view</a></th><%} %>
				</tr>
				<%
						size++;
					} %>
		</table>
	</fieldset>
	<script type="text/javascript">
		displayTable(<%=size%>);
	</script>
</div>
